package com.emm.yixun.mobile.ui.housing;

import android.annotation.SuppressLint;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnKeyListener;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.alibaba.fastjson.JSONObject;
import com.emm.yixun.mobile.R;
import com.emm.yixun.mobile.application.EmmApplication;
import com.emm.yixun.mobile.base.BaseActivity;
import com.emm.yixun.mobile.model.AddProjectRealMap;
import com.emm.yixun.mobile.model.GetHousesDetail;
import com.emm.yixun.mobile.model.GetHousesDetail.RealMapList;
import com.emm.yixun.mobile.ui.signed.NewSignedActivity;
import com.emm.yixun.mobile.ui.subscribe.NewSubscribeActivity;
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestParams;
import com.nui.multiphotopicker.view.ImageBucketChooseActivity;
import com.yanzhenjie.album.Album;
import com.yixun.app.viewpagerandimag.sample.ViewPagerActivity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import me.imid.swipebacklayout.lib.SwipeBackLayout;
import me.imid.swipebacklayout.lib.app.SwipeBackActivity;
import xf.tools.Loading;

/**
 * <p>
 * <b>Title：</b> 房源详情
 * </p>
 * <p>
 * <b>Description：</b>
 * </p>
 *
 * @author tangxin
 * @date 2016年12月6日 下午4:11:13
 */
public class HouSingResourcesDetailsActivity extends SwipeBackActivity {

    private final static String TAG = "HouSingResourcesDetailsActivity";

    /**
     * 页头标题
     */
    TextView title_main;

    /**
     * 项目名-组团名-楼栋....
     */
    TextView pr_name;

    /**
     * 房源状态
     */
    EditText housesStatus_view;

    /**
     * 计价方式
     */
    EditText pricingMode_view;

    /**
     * 户型
     */
    EditText housesType_view;

    /**
     * 建筑面积
     */
    EditText buildingArea_view;

    /**
     * 套内面积
     */
    EditText innerArea_view;

    /**
     * 分摊面积
     */
    EditText sharingArea_view;

    /**
     * 赠送面积
     */
    EditText freeArea_view;

    /**
     * 建筑单价
     */
    EditText buildingPrice_view;

    /**
     * 套内单价
     */
    EditText innerPrice_view;

    /**
     * 总价
     */
    EditText totalAmount_view;

    /**
     * 打开相册gridview
     */
    ImageView open_grid;

    /**
     * 相册数量
     */
    TextView realMapList_view;

    /**
     * 相册或拍照
     */
    ImageView open_view;

    private String roomId = "";

    /**
     * 返回按钮
     */
    ImageView back_btn;

    /**
     * 头像菜单
     */
    public View view3;

    /**
     * 头像菜单
     */
    public PopupWindow popu_phone;

    public static String DeleteUrl = "";

    public String realMapId;

    /**
     * 签约，认购
     */
    Button btnSign, btnSubscribe;

    ArrayList<RealMapList> ImagePatch = new ArrayList<RealMapList>();

    /**
     * true 显示 false隐藏
     */
    private boolean IsOpen = false;

    /**
     * 展示相册布局
     */
    LinearLayout ph_linear, container;

    /**
     * 图片列表
     */
    GridView ph_grid;

    /**
     * 侧滑关闭框架
     */
    private SwipeBackLayout mSwipeBackLayout;

    private LinearLayout llCustomerName, llSaleMan;
    private View line1, line2;
    private TextView tvCustomerName, tvSalesMan;

    @Override
    protected void onCreate(Bundle arg0) {
        super.onCreate(arg0);
        setContentView(R.layout.housing_details_actiivty);

        SetSwipeBackLayout(mSwipeBackLayout);

        BaseActivity.activity = this;

        roomId = getIntent().getStringExtra("roomId");
        Log.v(TAG, "roomId:" + roomId);

        initView();

        SetRelativiLayoutPadding(R.id.main_head_top_rela);

        initBtn();
        GetHousesDetail();
    }

    /**
     * <p>
     * <b>Title：</b> 初始化view
     * </p>
     * <p>
     * <b>Description：</b>
     * </p>
     *
     * @author tangxin
     * @date 2016年12月7日 下午3:30:41
     */
    private void initView() {
        llCustomerName = (LinearLayout) findViewById(R.id.ll_customer_name);
        llSaleMan = (LinearLayout) findViewById(R.id.ll_sales_man);
        line1 = findViewById(R.id.line1);
        line2 = findViewById(R.id.line2);
        tvCustomerName = (TextView) findViewById(R.id.tv_customer_name);
        tvSalesMan = (TextView) findViewById(R.id.tv_sales_man);
        pr_name = (TextView) findViewById(R.id.pr_name);
        housesStatus_view = (EditText) findViewById(R.id.housesStatus_view);
        pricingMode_view = (EditText) findViewById(R.id.pricingMode_view);
        buildingArea_view = (EditText) findViewById(R.id.buildingArea_view);
        innerArea_view = (EditText) findViewById(R.id.innerArea_view);
        sharingArea_view = (EditText) findViewById(R.id.sharingArea_view);
        freeArea_view = (EditText) findViewById(R.id.freeArea_view);
        buildingPrice_view = (EditText) findViewById(R.id.buildingPrice_view);
        innerPrice_view = (EditText) findViewById(R.id.innerPrice_view);
        totalAmount_view = (EditText) findViewById(R.id.totalAmount_view);
        open_grid = (ImageView) findViewById(R.id.open_grid);
        realMapList_view = (TextView) findViewById(R.id.realMapList_view);
        open_view = (ImageView) findViewById(R.id.open_view);
        title_main = (TextView) findViewById(R.id.title_main);
        title_main.setText(R.string.content_housing);
        back_btn = (ImageView) findViewById(R.id.back_btn);
        btnSign = (Button) findViewById(R.id.btn_sign);
        btnSubscribe = (Button) findViewById(R.id.btn_subscribe);
        ph_linear = (LinearLayout) findViewById(R.id.ph_linear);
        ph_grid = (GridView) findViewById(R.id.ph_grid);
        housesType_view = (EditText) findViewById(R.id.housesType_view);
        container = (LinearLayout) findViewById(R.id.btn);
    }

    /**
     * 在处理onKeyDown事件中调用Back工具类方法即可
     */
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            if (IsOpen) {
                IsOpen = false;
                ph_linear.setVisibility(View.GONE);
                return false;
            } else {
                finish();
            }
        } else {
        }
        return super.onKeyDown(keyCode, event);
    }

    /**
     * <p>
     * <b>Title：</b> 初始化监听事件
     * </p>
     * <p>
     * <b>Description：</b>
     * </p>
     *
     * @author tangxin
     * @date 2016年12月7日 下午3:30:57
     */
    private void initBtn() {
        back_btn.setVisibility(View.VISIBLE);
        back_btn.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (IsOpen) {
                    IsOpen = false;
                    ph_linear.setVisibility(View.GONE);
                } else {
                    finish();
                }
            }
        });
        open_view.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                popu();
            }
        });
        open_grid.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                //
                if (IsOpen) {
                    IsOpen = false;
                    ph_linear.setVisibility(View.GONE);

                } else {
                    IsOpen = true;
                    ph_linear.setVisibility(View.VISIBLE);

                }

            }
        });

        btnSubscribe.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(HouSingResourcesDetailsActivity.this, NewSubscribeActivity.class);
                intent.putExtra("OpenType", "1");
                intent.putExtra(NewSubscribeActivity.ROOM_ID, roomId);
                intent.putExtra(NewSubscribeActivity.HOUSE_DETAIL, gethouses);
                startActivity(intent);
            }
        });
        btnSign.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(HouSingResourcesDetailsActivity.this, NewSignedActivity.class);
                intent.putExtra("OpenType", "1");
                intent.putExtra("FrdID", roomId);
                intent.putExtra(NewSubscribeActivity.HOUSE_DETAIL, gethouses);
                startActivity(intent);
            }
        });

    }

    @Override
    protected void onResume() {
        super.onResume();
        BaseActivity.activity = this;
        if (null != EmmApplication.pir || EmmApplication.pir.size() > 0) {
            Loading.showDialogForLoading(HouSingResourcesDetailsActivity.this, "正在转码提交.", false, true, 100000);
            RecordTaskUpdate record = new RecordTaskUpdate();
            record.execute();
        }
        IntentFilter filter = new IntentFilter(EmmApplication.NEWHousing);
        registerReceiver(mBroadcastReceiver, filter);
    }

    /**
     * 接收广播，刷新动作
     */
    private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (action.equals(EmmApplication.NEWHousing)) {
                // 刷新动作
                Log.v(TAG, "---------刷新动作- NEWHousing ---------");
                for (int i = 0; i < ImagePatch.size(); i++) {
                    if (DeleteUrl.equals(ImagePatch.get(i).getRealMapUrl())) {
                        realMapId = ImagePatch.get(i).getRealMapId();
                        ImagePatch.remove(i);
                        continue;
                    }
                }
                delProjectRealMap();
            }
        }
    };

    @Override
    protected void onDestroy() {
        super.onDestroy();
        unregisterReceiver(mBroadcastReceiver);
        EmmApplication.pir.clear();
        Log.v(TAG, "EmmApplication.pir:" + EmmApplication.pir.size());
        ImagePatch.clear();
    }

    String path;

    /**
     * 回调方法
     */
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        Log.w("a", +requestCode + "resultCode===" + resultCode + "RESULT_OK======" + RESULT_OK);
        if (resultCode != RESULT_OK) {
            return;
        }
        switch (requestCode) {
            case PICK_FROM_CAMERA:
                path = Album.parseResult(data).get(0);
                Log.w("a", "拍照:+>" + path);

                handler.sendEmptyMessage(123);


                break;
            case 0:
                System.out.println("相册");
                break;
            default:
                break;
        }
    }

    /**
     * 查询房源详情接口
     */
    GetHousesDetail gethouses;

    /**
     * <p>
     * <b>Title：</b> 房源详情查询接口
     * </p>
     * <p>
     * <b>Description：</b>
     * </p>
     *
     * @author tangxin
     * @date 2016年12月7日 下午3:31:41
     */
    private void GetHousesDetail() {
        EmmApplication.updateUrl("getHousesDetail");
        Map<String, String> map = new HashMap<String, String>();
        map.put("version", EmmApplication.getPackageManager(5));
        map.put("merchantId", EmmApplication.getData(EmmApplication.merchantId));
        map.put("token", EmmApplication.getToken());
        map.put("userId", EmmApplication.getUserId());
        map.put("projectCode", EmmApplication.getProjectCode());
        map.put("projectId", EmmApplication.getProjectID());
        map.put("terminalCode", EmmApplication.getPackageManager(2));
        map.put("roomId", roomId);
        Map<String, Object> paramsMap = new HashMap<String, Object>();
        paramsMap.put("params", map);
        JSONObject json = new JSONObject(paramsMap);
        String jsonstr = json.toString();
        RequestParams params = new RequestParams();
        params.put("body", jsonstr);
        Log.v("getHousesDetail-->post", EmmApplication.urlStr + "?body=" + jsonstr);
        AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
        asyncHttpClient.post(EmmApplication.urlStr, params, new AsyncHttpResponseHandler() {
            @Override
            public void onFailure(Throwable error, String content) {
                super.onFailure(error, content);
                Loading.hideDialogForLoading();
                Log.v(TAG, "请求结束error:" + error + "==" + content);
            }

            @Override
            public void onFinish() {
                Loading.hideDialogForLoading();
                Log.v(TAG, "请求结束");
                super.onFinish();
            }

            @Override
            public void onStart() {
                super.onStart();
                Loading.showDialogForLoading(HouSingResourcesDetailsActivity.this, "正在加载...", false, true, 60000);
                Log.v(TAG, "请求开始");
            }

            @Override
            public void onSuccess(String content) {
                super.onSuccess(content);
                if (content == null) {
                    return;
                }
                Log.v(TAG, content);
                JSONObject jsonObj = JSONObject.parseObject(content);
                JSONObject resData = (JSONObject) jsonObj.get("resData");
                if (resData == null) {
                    Log.v(TAG, "信息返回值为空");
                    return;
                }

                gethouses = JSONObject.parseObject(resData.toString(), GetHousesDetail.class);

                if ("1".equals(gethouses.getResult())) {
                    Log.v("获取成功", "");

                    EmmApplication.image(R.drawable.suanjia_img);
                    if (null != gethouses.getRealMapList() && gethouses.getRealMapList().size() > 0) {
                        EmmApplication.imageLoader.displayImage(gethouses.getRealMapList().get(0).getRealMapUrl(),
                                open_grid);
                    }
                    container.setVisibility("可售".equals(gethouses.getHousesStatus()) ? View.VISIBLE : View.GONE);
                    pr_name.setText(IsNull(gethouses.getHousesName()) == true ? gethouses.getHousesName() : "");

                    housesStatus_view.setText(IsNull(gethouses.getHousesStatus()) == true ? gethouses.getHousesStatus()
                            : "");

                    pricingMode_view.setText(IsNull(gethouses.getPricingMode()) == true ? gethouses.getPricingMode()
                            : "");

                    try {
                        housesType_view.setText(IsNull(gethouses.getHousesType()) == true ? gethouses.getHousesType()
                                : "");
                    } catch (NullPointerException e) {
                        housesType_view.setText("");
                    }

                    buildingArea_view.setText(IsNull(gethouses.getBuildingArea()) == true ? gethouses.getBuildingArea()
                            : "");

                    innerArea_view.setText(IsNull(gethouses.getInnerArea()) == true ? gethouses.getInnerArea() : "");

                    sharingArea_view.setText(IsNull(gethouses.getSharingArea()) == true ? gethouses.getSharingArea()
                            : "");

                    freeArea_view.setText(IsNull(gethouses.getFreeArea()) == true ? gethouses.getFreeArea() : "");

                    buildingPrice_view.setText(IsNull(gethouses.getBuildingPrice()) == true ? gethouses
                            .getBuildingPrice() : "");

                    innerPrice_view.setText(IsNull(gethouses.getInnerPrice()) == true ? gethouses.getInnerPrice() : "");

                    totalAmount_view.setText(IsNull(gethouses.getTotalAmount()) == true ? gethouses.getTotalAmount()
                            : "");

                    if (null != gethouses.getRealMapList()) {
                        ImagePatch.clear();
                        for (int i = 0; i < gethouses.getRealMapList().size(); i++) {
                            ImagePatch.add(gethouses.getRealMapList().get(i));
                        }
                        realMapList_view.setText("(" + gethouses.getRealMapList().size() + ")");
                        ph_grid.setAdapter(new GridAdapter(ImagePatch));
                        Log.v(TAG, "size():==>" + gethouses.getRealMapList().size());
                    } else {
                        realMapList_view.setText("(0)");
                    }
                    if (TextUtils.isEmpty(gethouses.getCustomerName())) {
                        llCustomerName.setVisibility(View.GONE);
                        line1.setVisibility(View.GONE);
                        tvCustomerName.setVisibility(View.GONE);
                    } else {
                        tvCustomerName.setText(gethouses.getCustomerName());
                    }
                    if (TextUtils.isEmpty(gethouses.getUserName())) {
                        llSaleMan.setVisibility(View.GONE);
                        line2.setVisibility(View.GONE);
                        tvSalesMan.setVisibility(View.GONE);
                    } else {
                        tvSalesMan.setText(gethouses.getUserName());
                    }

                    final boolean availableSale = "可售".equals(gethouses.getHousesStatus());

                    final boolean isAddSubscribe = "1".equals(EmmApplication.getData(EmmApplication.isAddSubscribe));
                    final boolean isAddSigned = "1".equals(EmmApplication.getData(EmmApplication.isAddSigned));

                    btnSubscribe.setVisibility(isAddSubscribe && availableSale ? View.VISIBLE : View.GONE);
                    btnSign.setVisibility(isAddSigned && availableSale ? View.VISIBLE : View.GONE);
                } else {
                    EmmApplication.T(gethouses.getErrorMsg().toString());
                    Log.v("获取失败", "errorCode:" + gethouses.getErrorCode().toString() + "errorMsg:"
                            + gethouses.getErrorMsg().toString());
                }
            }
        });
    }

    /**
     * 判String断是否为空
     */
    private boolean IsNull(String str) {
        if (null == str || "".equals(str) || TextUtils.isEmpty(str) || "null".equals(str)) {
            return false;
        } else {
            return true;
        }
    }

    /**
     * 拍照图片路径
     */
    private Uri mImageCaptureUri;

    private static final int PICK_FROM_CAMERA = 1;

    /**
     * <p>
     * <b>Title：</b> 点击后的弹出框
     * </p>
     * <p>
     * <b>Description：</b>
     * </p>
     *
     * @author tangxin
     * @date 2016年12月7日 下午3:32:06
     */
    public void popu() {
        view3 = LayoutInflater.from(HouSingResourcesDetailsActivity.this).inflate(R.layout.item_popupwindow, null);
        popu_phone = new PopupWindow(view3, android.support.v4.view.ViewPager.LayoutParams.FILL_PARENT,
                android.support.v4.view.ViewPager.LayoutParams.FILL_PARENT);
        popu_phone.setFocusable(true);

        popu_phone.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

        popu_phone.showAtLocation(view3, Gravity.BOTTOM, 0, 0);
        popu_phone.showAsDropDown(view3, 0, 0);
        popu_phone.setFocusable(true);
        popu_phone.setOutsideTouchable(true);
        view3.setFocusable(true);
        view3.setFocusableInTouchMode(true);

        view3.setOnKeyListener(new OnKeyListener() {
            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                if (keyCode == KeyEvent.KEYCODE_BACK) {
                    popu_phone.dismiss();
                    EmmApplication.setLog(HouSingResourcesDetailsActivity.this);
                }
                return false;
            }
        });

        view3.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                popu_phone.dismiss();
                EmmApplication.setLog(HouSingResourcesDetailsActivity.this);
            }
        });

        // 拍照
        Button item_popupwindows_camera = (Button) view3.findViewById(R.id.item_popupwindows_camera);
        // 相册
        Button item_popupwindows_Photo = (Button) view3.findViewById(R.id.item_popupwindows_Photo);
        // 取消
        Button item_popupwindows_cancel = (Button) view3.findViewById(R.id.item_popupwindows_cancel);

        item_popupwindows_cancel.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                popu_phone.dismiss();
                EmmApplication.setLog(HouSingResourcesDetailsActivity.this);
            }
        });
        item_popupwindows_camera.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                popu_phone.dismiss();
                EmmApplication.setLog(HouSingResourcesDetailsActivity.this);
                Album.camera(activity).start(PICK_FROM_CAMERA);
            }
        });
        item_popupwindows_Photo.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                EmmApplication.bitmap = null;
                popu_phone.dismiss();
                EmmApplication.setLog(HouSingResourcesDetailsActivity.this);
                EmmApplication.setData("Picture", "1");
                EmmApplication.IsMoreSelect = true;
                startActivity(new Intent(HouSingResourcesDetailsActivity.this, ImageBucketChooseActivity.class));
            }
        });
    }

    class GridAdapter extends BaseAdapter {

        ArrayList<RealMapList> list;

        public GridAdapter(ArrayList<RealMapList> list) {
            this.list = list;
        }

        @Override
        public int getCount() {
            return list == null ? 0 : list.size();
        }

        @Override
        public Object getItem(int position) {
            return list == null ? null : list.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {
            ViewHoudlerP v = null;
            if (convertView == null) {
                convertView = LayoutInflater.from(HouSingResourcesDetailsActivity.this).inflate(R.layout.image_item,
                        null);
                v = new ViewHoudlerP();
                v.p_image = (ImageView) convertView.findViewById(R.id.p_image);
                convertView.setTag(v);
            } else {
                v = (ViewHoudlerP) convertView.getTag();
            }
            EmmApplication.image(R.drawable.suanjia_img);
            EmmApplication.imageLoader.displayImage(list.get(position).getRealMapUrl(), v.p_image);

            Log.v(TAG, "position:" + position);

            convertView.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    ViewPagerActivity.postion = position;
                    ViewPagerActivity.sDrawables.clear();

                    for (int u = 0; u < list.size(); u++) {
                        ViewPagerActivity.sDrawables.add(list.get(u).getRealMapUrl());
                    }
                    Intent intent = new Intent(HouSingResourcesDetailsActivity.this, ViewPagerActivity.class);
                    intent.putExtra("IsOpenDelete", 2);
                    intent.putExtra("HouSingResources", "1");
                    startActivity(intent);
                }
            });

            return convertView;
        }

    }

    public static class ViewHoudlerP {
        ImageView p_image;
    }

    public class RealMapListinfo {
        private String realMapType;// 实景图类型
        private String realMapContent;// 实景图内容

        public String getRealMapType() {
            return realMapType;
        }

        public void setRealMapType(String realMapType) {
            this.realMapType = realMapType;
        }

        public String getRealMapContent() {
            return realMapContent;
        }

        public void setRealMapContent(String realMapContent) {
            this.realMapContent = realMapContent;
        }
    }

    /**
     * 新增项目实景图接口(addProjectRealMap)
     */
    AddProjectRealMap addRea;

    /**
     * <p>
     * <b>Title：</b> 实景图新增接口
     * </p>
     * <p>
     * <b>Description：</b>
     * </p>
     *
     * @param realMapList
     * @author tangxin
     * @date 2016年12月7日 下午3:32:37
     */
    private void addProjectRealMap(ArrayList<RealMapListinfo> realMapList) {
        EmmApplication.updateUrl("addProjectRealMap");
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("version", EmmApplication.getPackageManager(5));
        map.put("merchantId", EmmApplication.getData(EmmApplication.merchantId));
        map.put("token", EmmApplication.getToken());
        map.put("userId", EmmApplication.getUserId());
        map.put("projectCode", EmmApplication.getProjectCode());
        map.put("projectId", EmmApplication.getProjectID());
        map.put("terminalCode", EmmApplication.getPackageManager(2));
        map.put("realMapList", realMapList);
        Map<String, Object> paramsMap = new HashMap<String, Object>();
        paramsMap.put("params", map);
        JSONObject json = new JSONObject(paramsMap);
        String jsonstr = json.toString();
        RequestParams params = new RequestParams();
        params.put("body", jsonstr);
        Log.v("addProjectRealMap-->post", EmmApplication.urlStr + "?body=" + jsonstr);
        AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
        asyncHttpClient.post(EmmApplication.urlStr, params, new AsyncHttpResponseHandler() {
            @Override
            public void onFailure(Throwable error, String content) {
                super.onFailure(error, content);
                Loading.hideDialogForLoading();
                Log.v(TAG, "请求结束error:" + error + "==" + content);
            }

            @Override
            public void onFinish() {
                Loading.hideDialogForLoading();
                Log.v(TAG, "请求结束");
                super.onFinish();
            }

            @Override
            public void onStart() {
                super.onStart();
                Log.v(TAG, "请求开始");
            }

            @Override
            public void onSuccess(String content) {
                super.onSuccess(content);
                if (content == null) {
                    return;
                }
                Log.v(TAG, content);
                JSONObject jsonObj = JSONObject.parseObject(content);
                JSONObject resData = (JSONObject) jsonObj.get("resData");
                if (resData == null) {
                    Log.v(TAG, "信息返回值为空");
                    return;
                }
                EmmApplication.pir.clear();
                addRea = JSONObject.parseObject(resData.toString(), AddProjectRealMap.class);
                Loading.hideDialogForLoading();
                if ("1".equals(addRea.getResult())) {
                    Log.v("获取成功", "");
                    handler.sendEmptyMessage(111);
                } else {
                    EmmApplication.T(addRea.getErrorMsg().toString());
                    Log.v("获取失败", "errorCode:" + addRea.getErrorCode().toString() + "errorMsg:"
                            + addRea.getErrorMsg().toString());
                }
            }
        });
    }

    @SuppressLint("HandlerLeak")
    Handler handler = new Handler() {
        public void handleMessage(android.os.Message msg) {
            if (msg.what == 111) {
                GetHousesDetail();
            } else if (msg.what == 121) {
                Loading.showDialogForLoading(HouSingResourcesDetailsActivity.this, "正在转码提交.", false, true, 100000);
                ArrayList<RealMapListinfo> contentList_ = new ArrayList<RealMapListinfo>();
                RealMapListinfo rlmp = new RealMapListinfo();
                rlmp.setRealMapContent(EmmApplication.setPatchRtString(path));
                rlmp.setRealMapType(".jpg");
                contentList_.add(rlmp);
                addProjectRealMap(contentList_);
            }
        }

    };

    class RecordTaskUpdate extends AsyncTask<Void, Integer, Void> {

        @Override
        protected Void doInBackground(Void... arg0) {
            ArrayList<RealMapListinfo> contentList_ = new ArrayList<RealMapListinfo>();
            for (int i = 0; i < EmmApplication.pir.size(); i++) {
                RealMapListinfo rlmp = new RealMapListinfo();
                rlmp.setRealMapContent(EmmApplication.setPatchRtString(EmmApplication.pir.get(i).sourcePath));
                rlmp.setRealMapType(".jpg");
                contentList_.add(rlmp);
            }
            addProjectRealMap(contentList_);
            return null;
        }

        // 当在上面方法中调用publishProgress时，该方法触发,该方法在I线程中被执行
        protected void onProgressUpdate(Integer... progress) {
        }

        protected void onPostExecute(Void result) {
        }

        protected void onPreExecute() {
        }
    }

    public class RealMapListinfo2 {
        private String realMapId;

        public String getRealMapId() {
            return realMapId;
        }

        public void setRealMapId(String realMapId) {
            this.realMapId = realMapId;
        }
    }

    /**
     * <p>
     * <b>Title：</b> 实景图删除接口
     * </p>
     * <p>
     * <b>Description：</b>
     * </p>
     *
     * @author tangxin
     * @date 2016年12月7日 下午3:33:04
     */
    private void delProjectRealMap() {
        EmmApplication.updateUrl("delProjectRealMap");
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("version", EmmApplication.getPackageManager(5));
        map.put("merchantId", EmmApplication.getData(EmmApplication.merchantId));
        map.put("token", EmmApplication.getToken());
        map.put("userId", EmmApplication.getUserId());
        map.put("projectCode", EmmApplication.getProjectCode());
        map.put("projectId", EmmApplication.getProjectID());
        map.put("terminalCode", EmmApplication.getPackageManager(2));
        RealMapListinfo2 r = new RealMapListinfo2();
        ArrayList<RealMapListinfo2> realMapList = new ArrayList<HouSingResourcesDetailsActivity.RealMapListinfo2>();
        r.setRealMapId(realMapId);
        realMapList.add(r);
        map.put("realMapList", realMapList);
        Map<String, Object> paramsMap = new HashMap<String, Object>();
        paramsMap.put("params", map);
        JSONObject json = new JSONObject(paramsMap);
        String jsonstr = json.toString();
        RequestParams params = new RequestParams();
        params.put("body", jsonstr);
        Log.v("delProjectRealMap-->post", EmmApplication.urlStr + "?body=" + jsonstr);
        AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
        asyncHttpClient.post(EmmApplication.urlStr, params, new AsyncHttpResponseHandler() {
            @Override
            public void onFailure(Throwable error, String content) {
                super.onFailure(error, content);
                Loading.hideDialogForLoading();
                Log.v(TAG, "请求结束error:" + error + "==" + content);
            }

            @Override
            public void onFinish() {
                Loading.hideDialogForLoading();
                Log.v(TAG, "请求结束");
                super.onFinish();
            }

            @Override
            public void onStart() {
                super.onStart();
                Log.v(TAG, "请求开始");
            }

            @Override
            public void onSuccess(String content) {
                super.onSuccess(content);
                if (content == null) {
                    return;
                }
                Log.v(TAG, content);
                JSONObject jsonObj = JSONObject.parseObject(content);
                JSONObject resData = (JSONObject) jsonObj.get("resData");
                if (resData == null) {
                    Log.v(TAG, "信息返回值为空");
                    return;
                }
                EmmApplication.pir.clear();
                addRea = JSONObject.parseObject(resData.toString(), AddProjectRealMap.class);
                Loading.hideDialogForLoading();
                if ("1".equals(addRea.getResult())) {
                    Log.v("获取成功", "");

                    GetHousesDetail();

                    EmmApplication.T("删除成功");

                } else {
                    EmmApplication.T(addRea.getErrorMsg().toString());
                    Log.v("获取失败", "errorCode:" + addRea.getErrorCode().toString() + "errorMsg:"
                            + addRea.getErrorMsg().toString());
                }
            }
        });
    }

}
